package com.he;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class MyBatisPlusGenerator {
    // 处理 all 情况
    protected static List<String> getTables(String tables) {
        return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
    }

    public static void main(String[] args) {
        FastAutoGenerator.create(
//                        "jdbc:mysql://localhost:3306/my_database?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false",
//                        "root",
//                        "root"
                "jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 172.18.3.25)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = ykgtdb)))",
                "slmesuser",
                "YKgtGYhlw2023"
                )


                // 全局配置
                .globalConfig((scanner, builder) -> {
//                    builder.author(scanner.apply("请输入作者名称？")).fileOverride();
                    builder.author("hcl").fileOverride();
//                    builder.enableSwagger();
//                    builder.outputDir("E:\\study\\SpringCloud\\mybatisplus\\src\\main\\java");
                    builder.outputDir(System.getProperty("user.dir") + "\\src\\main\\java");
                })
                // 包配置
                .packageConfig((scanner, builder) -> {
//                    builder.parent(scanner.apply("请输入包名？"));
                    builder.parent("res");
                })
                // 策略配置
                .strategyConfig((scanner, builder) -> {
//                    builder.addInclude(MyBatisPlusGenerator.getTables(scanner.apply("请输入表名，多个英文逗号分隔？所有输入 all")))
                    builder.addInclude(MyBatisPlusGenerator.getTables("TGR_STOP_RECORD"))
                            .controllerBuilder().enableRestStyle().enableHyphenStyle()
                            .build();

                    builder.serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImp")
                            .build();

                    //entity的策略配置
                    builder.entityBuilder()
                            .disableSerialVersionUID()
                            .enableLombok()
                            .enableTableFieldAnnotation()
//                            .versionColumnName("version")
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .idType(IdType.AUTO)
                            .formatFileName("%sDO")
                            .addSuperEntityColumns("id", "created_by", "created_time", "updated_by", "updated_time")
//                            .addTableFills(new Column("create_time", FieldFill.INSERT))
//                            .addTableFills(new Property("updateTime", FieldFill.INSERT_UPDATE))
//                            .logicDeleteColumnName("is_delete")
                            .build();
                })
                .execute();
    }
}
